/* @(#)GSBusOrderRefundSubmitAction.java    V0.1
 *
 * Project: GSdevelop
 * 
 */
package com.hitrust.gs.action;

import java.text.SimpleDateFormat;
import java.util.HashMap;

import com.hitrust.gs.bean.GSOperatorBean;
import com.hitrust.gs.business.GSManufactureProcessor;
import com.hitrust.gs.business.GSOrderDeptInfoProcessor;
import com.hitrust.gs.business.GSOrderProcessor;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.util.exception.GSException;

/**
 * 更新巴士物资订单退货
 */
public class GSBusOrderRefundSubmitAction extends GSBaseAction
{

    public String execute(GSBaseForm aForm) throws Exception 
    {
        String tOrderid = aForm.getRequest().getParameter("orderid");
        String refundcount = aForm.getRequest().getParameter("refundcount");
        String tContents = aForm.getRequest().getParameter("contents");
        String tStatus = aForm.getRequest().getParameter("status");
        
        String tIsTradeFlatManuf = aForm.getRequest().getParameter("isTradeFlatManuf");
        String tIsTradeFlatProv = aForm.getRequest().getParameter("isTradeFlatProvider");
        
        GSOperatorBean tOperBean = (GSOperatorBean)aForm.getSession().getAttribute(GSBaseConstants.LOGIN);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String buf = df.format(new java.util.Date(System.currentTimeMillis()));
        String tOrderDetailStatus = null;
        
        //订单明细状态为退货申请
        tOrderDetailStatus = GSBaseConstants.ORDER_REFUND_APPLITION;
        
        try
        {
            String returnValue = GSOrderProcessor.doRefundBusOrderTask(tStatus,tOrderDetailStatus,tOrderid,tOperBean,buf,refundcount,tContents,tIsTradeFlatManuf,tIsTradeFlatProv);
            if(returnValue != null && !returnValue.equals(""))
            {
                aForm.getRequest().setAttribute("message","订单退货执行成功,生成新的退货单：" + returnValue);
            }else{
                aForm.getRequest().setAttribute("message","订单退货执行失败");
            }
        }
        catch(GSException ge)
        {
            aForm.getRequest().setAttribute("message","订单退货执行失败");
            aForm.getRequest().setAttribute("window","true");
            throw ge;
        }
        catch(Exception e)
        {
            aForm.getRequest().setAttribute("message","订单退货执行失败");
            aForm.getRequest().setAttribute("window","true");
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E10044,GSException.E10044_MSG);
        }
        
        GSOrderDeptInfoProcessor tOrderDeptInfoProc = new GSOrderDeptInfoProcessor();
        //巴士物资级操作员可操作订货单位及送货地址
        HashMap tMap = tOrderDeptInfoProc.getOrderDeptInfoOfBusOper(tOperBean.getGs_oper_org_id());
        aForm.getRequest().setAttribute("orderdept",tMap);
        //种类等级
        GSManufactureProcessor tGSManufProcessor = new GSManufactureProcessor();
        tGSManufProcessor.getManufactureOfLevel(aForm);
        
        //aForm.getRequest().setAttribute("orderStatus",tStatus);
        
        aForm.getRequest().setAttribute("requery","true");
        return GSBaseConstants.FORWARD_SUCCESS;
    }

}
